package com.mdd.admin.controller.customer;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICustomerDetailService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.customer.CustomerDetailCreateValidate;
import com.mdd.admin.validate.customer.CustomerDetailUpdateValidate;
import com.mdd.admin.validate.customer.CustomerDetailSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.customer.CustomerDetailListedVo;
import com.mdd.admin.vo.customer.CustomerDetailDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/customerDetail")
@Api(tags = "客户详情管理")
public class CustomerDetailController {

    @Resource
    ICustomerDetailService iCustomerDetailService;

    @GetMapping("/list")
    @ApiOperation(value="客户详情列表")
    public AjaxResult<PageResult<CustomerDetailListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated CustomerDetailSearchValidate searchValidate) {
        PageResult<CustomerDetailListedVo> list = iCustomerDetailService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户详情详情")
    public AjaxResult<CustomerDetailDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CustomerDetailDetailVo detail = iCustomerDetailService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户详情新增")
    @PostMapping("/add")
    @ApiOperation(value="客户详情新增")
    public AjaxResult<Object> add(@Validated @RequestBody CustomerDetailCreateValidate createValidate) {
        iCustomerDetailService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户详情编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户详情编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CustomerDetailUpdateValidate updateValidate) {
        iCustomerDetailService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户详情删除")
    @PostMapping("/del")
    @ApiOperation(value="客户详情删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCustomerDetailService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
